package org.example.clouddemo.bean.common.enums;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 产品分类枚举
 */
@Getter
@AllArgsConstructor
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum ProductCategoryEnum {
    
    ELECTRONICS("electronics", "电子产品"),
    CLOTHING("clothing", "服装"),
    FOOD("food", "食品"),
    BOOKS("books", "书籍"),
    HOME_APPLIANCES("home_appliances", "家用电器"),
    BEAUTY("beauty", "美妆"),
    SPORTS("sports", "运动"),
    FURNITURE("furniture", "家具"),
    TOYS("toys", "玩具"),
    OTHERS("others", "其他");
    
    private final String code;
    private final String name;
    
    /**
     * 根据code获取枚举
     */
    public static ProductCategoryEnum getByCode(String code) {
        for (ProductCategoryEnum category : values()) {
            if (category.getCode().equals(code)) {
                return category;
            }
        }
        return OTHERS;
    }
    
    /**
     * 获取中文名称
     */
    public String getName() {
        return name;
    }
}